<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Prototype Unit test file</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <script src="../../dist/prototype.js" type="text/javascript"></script>
  <script src="../lib/unittest.js" type="text/javascript"></script>
  <link rel="stylesheet" href="../test.css" type="text/css" />
  <style type="text/css" media="screen">
  /* <![CDATA[ */
    #testcss1 { font-size:11px; color: #f00; }
    #testcss2 { font-size:12px; color: #0f0; display: none; }
  /* ]]> */
  </style>
</head>
<body>
<h1>Prototype Unit test file</h1>
<p>
  Test of utility functions in selector.js
</p>

<div id="fixtures" style="display: none">
  <h1 class="title">Some title <span>here</span></h1>
  <p id="p" class="first summary">
    <strong id="strong">This</strong> is a short blurb
    <a id="link_1" class="first internal" href="#">with a link</a> or 
    <a id="link_2" class="internal highlight" href="#"><em id="em">two</em></a>.
  </p>
  <ul id="list">
    <li id="item_1" class="first"><a id="link_3" href="#" class="external"><span id="span">Another link</span></a></li>
    <li id="item_2">Some text</li>
		<li id="item_3" xml:lang="es-us" class="">Otra cosa</li>
  </ul>
</div>

<!-- Log output -->
<div id="testlog"> </div>

<!-- Tests follow -->
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
  new Test.Unit.Runner({
    testSelectorWithTagName: function() {with(this) {
      assertEnumEqual($A(document.getElementsByTagName('li')), $$('li'));
      assertEnumEqual([$('strong')], $$('strong'));
      assertEnumEqual([], $$('nonexistent'));
      assertEnumEqual($A(document.getElementsByTagName('*')), $$('*'));
    }},
    
    testSelectorWithId: function() {with(this) {
      assertEnumEqual([$('fixtures')], $$('#fixtures'));
      assertEnumEqual([], $$('#nonexistent'));
    }},
    
    testSelectorWithClassName: function() {with(this) {
      assertEnumEqual($('p', 'link_1', 'item_1'), $$('.first'));
      assertEnumEqual([], $$('.second'));
    }},
    
    testSelectorWithTagNameAndId: function() {with(this) {
      assertEnumEqual([$('strong')], $$('strong#strong'));
      assertEnumEqual([], $$('p#strong'));
    }},
    
    testSelectorWithTagNameAndClassName: function() {with(this) {
      assertEnumEqual($('link_1', 'link_2'), $$('a.internal'));
      assertEnumEqual([$('link_2')], $$('a.internal.highlight'));
      assertEnumEqual([$('link_2')], $$('a.highlight.internal'));
      assertEnumEqual([], $$('a.highlight.internal.nonexistent'));
    }},
    
    testSelectorWithIdAndClassName: function() {with(this) {
      assertEnumEqual([$('link_2')], $$('#link_2.internal'));
      assertEnumEqual([$('link_2')], $$('.internal#link_2'));
      assertEnumEqual([$('link_2')], $$('#link_2.internal.highlight'));
      assertEnumEqual([], $$('#link_2.internal.nonexistent'));
    }},
    
    testSelectorWithTagNameAndIdAndClassName: function() {with(this) {
      assertEnumEqual([$('link_2')], $$('a#link_2.internal'));
      assertEnumEqual([$('link_2')], $$('a.internal#link_2'));
      assertEnumEqual([$('item_1')], $$('li#item_1.first'));
      assertEnumEqual([], $$('li#item_1.nonexistent'));
      assertEnumEqual([], $$('li#item_1.first.nonexistent'));
    }},
    
    test$$MatchesAncestryWithTokensSeparatedByWhitespace: function() {with(this) {
      assertEnumEqual($('em', 'span'), $$('#fixtures a *'));
      assertEnumEqual([$('p')], $$('div#fixtures p'));
    }},
    
    test$$CombinesResultsWhenMultipleExpressionsArePassed: function() {with(this) {
      assertEnumEqual($('link_1', 'link_2', 'item_1', 'item_2', 'item_3'), $$('#p a', ' ul#list li '));
    }},

    testSelectorWithTagNameAndAttributeExistence: function() {with(this) {
      assertEnumEqual($$('#fixtures h1'), $$('h1[class]'));
      assertEnumEqual($$('#fixtures h1'), $$('h1[CLASS]'));
      assertEnumEqual([$('item_3')], $$('li#item_3[class]'));
    }},
    
    testSelectorWithTagNameAndSpecificAttributeValue: function() {with(this) {
      assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href="#"]'));
      assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href=#]'));
    }},
    
    testSelectorWithTagNameAndWhitespaceTokenizedAttributeValue: function() {with(this) {
      assertEnumEqual($('link_1', 'link_2'), $$('a[class~="internal"]'));
      assertEnumEqual($('link_1', 'link_2'), $$('a[class~=internal]'));
    }},
    
    testSelectorWithUniversalAndHyphenTokenizedAttributeValue: function() {with(this) {
      assertEnumEqual([$('item_3')], $$('*[xml:lang|="es"]'));
      assertEnumEqual([$('item_3')], $$('*[xml:lang|="ES"]'));
    }},
    
    testSelectorWithTagNameAndNegatedAttributeValue: function() {with(this) {
      assertEnumEqual([], $$('a[href!=#]'));
    }},
    
    test$$WithNestedAttributeSelectors: function() {with(this) {
      assertEnumEqual([$('strong')], $$('div[style] p[id] strong'));
    }},
    
    testSelectorWithMultipleConditions: function() {with(this) {
      assertEnumEqual([$('link_3')], $$('a[class~=external][href="#"]'));
      assertEnumEqual([], $$('a[class~=external][href!="#"]'));
    }},
    
    testSelectorMatchElements: function() {with(this) {
      assertElementsMatch(Selector.matchElements($('list').descendants(), 'li'), '#item_1', '#item_2', '#item_3');
      assertElementsMatch(Selector.matchElements($('fixtures').descendants(), 'a.internal'), '#link_1', '#link_2');
      assertEnumEqual([], Selector.matchElements($('fixtures').descendants(), 'p.last'));
    }},
    
    testSelectorFindElement: function() {with(this) {
      assertElementMatches(Selector.findElement($('list').descendants(), 'li'), 'li#item_1.first');
      assertElementMatches(Selector.findElement($('list').descendants(), 'li', 1), 'li#item_2');
      assertElementMatches(Selector.findElement($('list').descendants(), 'li#item_3'), 'li');
      assertEqual(undefined, Selector.findElement($('list').descendants(), 'em'));
    }}
  }, 'testlog');
// ]]>
</script>
</body>
</html>
